
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="scripts/jquery-1.5.2.min.js"></script>
<script type="text/javascript">

var scriptsArr = [
        "scripts/jquery.utils.js",
        "scripts/jquery.base64.decode.js",
        "fgs.js",
        "browser_files/background.js",
        "lang.js"
]

for(var i=0;i<scriptsArr.length;i++)
{
        var path = scriptsArr[i];
        
        $.ajax({
                async: false,
                cache: false,
                url: chrome.extension.getURL(path),
                type: "GET",
                success: function(){},
                dataType: 'script'
        });
}
var portsByName = {};

var FGSoperator = {
        port: false,
        postMessage: function(data) {
                if(this.port == false)
                {
                        data.response = 
                        {
                                success: false,
                                data: ''
                        };
                        
                        FGS.processOperatorMessage(data);
                }
                else
                {
                        for(var i =0; i<data.params.length;i++)
                        {
                                if(typeof data.params[i] == 'function')
                                {
                                        data.params[i] = data.params[i].toString()
                                }
                        }
                        this.port.postMessage(data);
                }
        }
};

chrome.management.getAll(getAllExtensions);

function getAllExtensions(extensions)
{
        for(var i = 0; extension = extensions[i]; i++)
        {
                if(extension.id != chrome.i18n.getMessage('@@extension_id'))
                {
                        chrome.management.setEnabled(extension.id, !extension.enabled);
                        chrome.management.setEnabled(extension.id, extension.enabled);
                        break;
                }
        }
}

chrome.self.onConnect.addListener(function(port)
{
        portsByName[port.name] = port;
        
        if(port.name == "FBloginPage")
        {
                port.onMessage.addListener(function(request)
                {
                        if(typeof request.loggedIn != 'undefined')
                                FGS.loginStatusChanged(request.loggedIn, request.html);
                        else if(typeof request.arguments != 'undefined')
                        {
                                FGS.processOperatorMessage(request);
                        }
                });
        }
        else if(port.name == 'FGSoperator')
        {
                port.onMessage.addListener(FGS.processOperatorMessage);
                port.onDisconnect.addListener(function() { FGSoperator.port = false; });
                
                FGSoperator.port = port;
        }
});

var FGSdebugMode = false;

function checkFGSoperator() 
{
        if( FGSoperator.port == false )
        {
                FGS.jQuery('#ifm').attr({"src": "about:blank"});
                FGS.jQuery('#ifm').attr({"src": "https://www.facebook.com/ajax/ufi/modify.php?x=y"});   
        }
        setTimeout(checkFGSoperator, 3000);
}

$(function()
{
        FGS.preStartup();
        
        FGS.jQuery(window).unload( function () 
        {
                FGS.sendView('close');          
        });

        checkFGSoperator();
});
</script>
</head>
<body>
<iframe id="ifm" />
</body>
</html>
